package com.xj.api.bussiness.machin.web;

import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.xj.api.base.web.BaseController;
import com.xj.api.bussiness.machin.service.YzMachinInfoService;
import com.xj.common.base.common.bean.AbstractBean;
import com.xj.common.bussiness.machin.entity.YzMachinInfo;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author Mars
 * @since 2017-08-24
 */
@RestController
@RequestMapping("yzMachinInfo")
public class YzMachinInfoController extends BaseController{
	
	@Autowired
	private YzMachinInfoService yzMachinInfoService;
	
	@GetMapping("/list.auth")
	@ApiOperation(value = "  列表", httpMethod = "GET", notes = "  列表")
	public AbstractBean yzMachinInfoList(@RequestParam(required=false,defaultValue="0") Integer pageNum,@RequestParam(required=false,defaultValue="10") Integer pageSize){
		return json(yzMachinInfoService.selectMapsPage(new Page<YzMachinInfo>(pageNum, pageSize), new EntityWrapper<YzMachinInfo>()));
	}
	
	@GetMapping("/{phone}.auth")
	@ApiOperation(value = "获取机械设备詳情", httpMethod = "GET", notes = "根据id获取用户詳情")
	public AbstractBean yzMachinInfoContent(@PathVariable Integer id){
		return json(yzMachinInfoService.selectOne(new EntityWrapper<YzMachinInfo>().eq("id", id)));
	}
	
	
	
	
	@PostMapping("/save")
	@ApiOperation(value = "新增", httpMethod = "POST", notes = "新增")
	public AbstractBean add(YzMachinInfo yzMachinInfo){
		
		if(!yzMachinInfoService.insert(yzMachinInfo)){
		return error();
	    }
		return success();
	}
	
	
	

	
	
	@DeleteMapping("{id}/delete")
	@ApiOperation(value = "  删除", httpMethod = "POST", notes = " 删除")
    public AbstractBean delete(@PathVariable(required=true) Integer id) {	
		if(!yzMachinInfoService.deleteById(id)){
		return error();
		}
		return success();
    }
}
